#include <iostream>
#include <algorithm>
#include <cstring>
#define endl '\n'
using namespace std;
const int N = 1e4 + 10;

int a[N];
int b[N];

int main(){
	// freopen("tree.in", "r", stdin);
	// freopen("tree.out", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	while(m--){
		int l, r;
		cin >> l >> r;
		l++, r++;
		b[l]++, b[r + 1]--;
	}
	int res = 0;
	for(int i = 1; i <= n + 1; i++){
		a[i] = a[i - 1] + b[i];
		if(a[i] == 0) res++;
	}
	cout << res << endl;
	return 0;
}